package com.safeluck.scannerqcr.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.safeluck.scannerqcr.R;
import com.safeluck.scannerqcr.bean.Article;

import java.util.ArrayList;
import java.util.List;

/**
 * ScannerQCR
 * Created by lzw on 2017/12/4. 15:30:48
 * 邮箱：632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */

public class MoreAdapter extends RecyclerView.Adapter<MoreAdapter.VH>{

    private LayoutInflater mInflater;
    private List<Article> articleList =new ArrayList<>();

    @Override
    public VH onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.more_item,parent,false);
        final VH vh = new VH(view);
        vh.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        return vh;
    }

    public MoreAdapter(Context context) {
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public void onBindViewHolder(VH holder, int position) {
        Article article = getItem(position);
        holder.tv_des1.setText(article.getCategory());
        holder.tv_des2.setText(article.getTitle());
        holder.tv_des3.setText(article.getContent());
    }
    public Article getItem(int pos){
        return articleList.get(pos);
    }

    @Override
    public int getItemCount() {
        return articleList.size();
    }

    public void setDatas(List<Article> datas){
        articleList.clear();
        articleList.addAll(datas);
        notifyDataSetChanged();
    }

    class VH extends RecyclerView.ViewHolder{

        private TextView tv_des1,tv_des2,tv_des3;

        public VH(View itemView) {
            super(itemView);
            tv_des1 = itemView.findViewById(R.id.category);
            tv_des2 = itemView.findViewById(R.id.tv_title);
            tv_des3 = itemView.findViewById(R.id.tv_content);
        }
    }
}
